<!DOCTYPE html>
<html lang="zh">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>考勤登记表</title>
    <meta name="keywords" content="考勤 ">
    <meta name="description" content="考勤">
    <meta name="author" content="">
    <link rel="stylesheet" type="text/css" href="./static/bootstrap/css/bootstrap.min.css">

    <link rel="stylesheet" type="text/css" href="./static/css/style.css">
    <link rel="icon" href="./static/img/icon.png" type="image/png">
</head>
<style>
    body,
    html {
        margin: 0;
        padding: 0;
    }

    .title_label {
        top: 5px;
        height: 29px;
        width: 100%;
        color: rgba(255, 255, 255, 1);
        font-size: 20px;
        text-align: center;
        font-family: PingFangSC-bold;
        font-weight: 700;
    }

    .header_main {
        width: 100%;
        margin: auto;
        background-image: url(/static/img/head_bg.png);
        background-position: top -110px right 0px;
        height: auto;
        padding: 20px; 

        background-size: cover;
        background-size: 100%;
        background-repeat: no-repeat;
        color: dimgray;

    }

    .row {
        margin-top: 10px;
    }

    .m-l-30 {
        margin-left: 30px;
    }


    .buttoncontainer {
        text-align: center;
        height: 100vh;
        /* 使用视口高度单位，使容器占据整个视口高度 */
    }

    .submit {
        margin: auto;
        display: inline-block;
        color: white;
        background-color: #17ad74;
        width: 100%;
        height: 50px;
        border-radius: 10px;
        border: 0px; 
    }
</style>

<body id="mainAPP" class="header_main">
    <header id="home" class="container " style="margin-top: 0px; text-align: center;">
        <img src="../static/img/logo.png" style="margin-bottom: 5px;" width="95%" >
    </header>
    <div class="container " id="mainDiv" style="margin-top:50px;">
        <div class="row  margin-top-20 ">
            <div class=" offset-md-1 col-lg-8 col-md-9 ">
                <label for="username" class="form-label">姓名</label>
                <input type="text" class="form-control" id="username" placeholder="填写本人真实姓名">
            </div>
        </div>

        <div class="row  ">
            <div class=" offset-md-1 col-lg-8 col-md-9 ">
                <label for="sn" class="form-label">学号</label>
                <input type="text" class="form-control" id="sn" placeholder="填写本人学号">
            </div>
        </div>
        <div class="row  ">
            <div class=" offset-md-1 col-lg-5 col-md-5 ">
                <label for="classroom" class="form-label">地址</label>
                <input type="text" class="form-control" id="classroom" value="2-607" placeholder="填写现在你的教室名，例如信科楼607">
            </div>

            <div class=" offset-md-1 col-lg-4 col-md-4 ">
                <label for="record" class="form-label">分值</label>
                <input type="number" class="form-control" id="record" value="0" >
            </div>
        </div>
        <div class="row  ">
            <div class=" offset-md-1 col-lg-8 col-md-9 ">
                <label for="comments" class="form-label">备注</label>
                <textarea rows="5" class="form-control" id="comments" placeholder="填写备注"></textarea>
            </div>
        </div>
        <div class="row buttoncontainer">
            <div class=" offset-md-1 col-lg-8 col-md-9 ">
                <label for="comments" class="form-label"></label>
            <button type="button" class="submit" data-bs-toggle="modal" data-bs-target="#exampleModal"
                onclick="submitHandler() "> 提交 </button>
            </div>
        </div> 
    </div>
    <div class="modal" id="exampleModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">确认信息</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div id="userinfoDiv">信息错误</div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="save() "
                        data-bs-dismiss="modal">确定保存</button>
                </div>
            </div>
        </div>
    </div>
    <div style="position:absolute; bottom: 0px;left: 0; width: 100%;   background-color: #17ad74; " id="bottomBox">
        <div style="color: white; text-align: center;" id="userinfo">信息工程学院</div>
    </div>
    <script src="./static/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="./static/js/axios.min.js"></script>
    <script type="text/javascript">
        let userInfo = new Object();
        function submitHandler() { 
            userInfo.Name = document.getElementById("username").value;
            userInfo.Sn = document.getElementById("sn").value;
            userInfo.Classroom = document.getElementById("classroom").value;
            userInfo.Comments = document.getElementById("comments").value;
            userInfo.Record = document.getElementById("record").value;
            userInfo.Record = parseInt( userInfo.Record);
            document.getElementById("userinfoDiv").innerHTML =
                `<label>姓名:` + userInfo.Name + `</label><br/>` +
                `<label>学号:` + userInfo.Sn + `</label><br/>` +
                `<label>位置:` + userInfo.Classroom + `</label><br/>` +
                `<label>分值:` + userInfo.Record + `</label><br/>` +
                `<label>备注:` + userInfo.Comments + `</label><br/>`;
        }

        function save() {
            axios.post('/api/classmates/signIn', userInfo).then(function (response) {
                const userinfodata = response.data.user;
                const resultdata = response.data;
                if (resultdata.code > 0) {
                    var result =
                        `<div style="text-align:center ;">姓名:` + userinfodata.Name + `&nbsp;&nbsp;&nbsp;&nbsp;学号:` + userinfodata.Sn + `</div>` +

                        ` <table style="border:1px solid black ; width:100%;padding:10px">
                    <tr   style="border:1px solid black ; width:100%;padding:10px">
                        <th>上课地点</th> <th>签到时间</th><th>备注</th>
                    </tr>`;
                    resultdata.data.forEach(item => {
                        result += `<tr> `
                        result += `  <td>` + item.Classroom + `</td>`
                        result += `  <td>` + item.Createtime + `</td>`
                        result += `  <td>` + item.Comments + `</td>`
                        result += `</tr> `
                    });
                    result += ` </table>`;
                    document.getElementById("mainDiv").innerHTML = result;
                    alert("填写成功")
                } else {
                    alert(response.data.data)
                }
            }).catch(function (error) {
                alert(error)
            });
        }


    </script>

</body>

</html>